package com.pro.service.imple;

import com.pro.dao.UserMapper;
import com.pro.entity.User;
import com.pro.service.UserService;
import com.pro.utils.InformationUtils;
import com.pro.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.UnknownHostException;
import java.util.List;
import java.util.logging.Logger;

/**
 * @ClassName: UserServiceImple
 * @Author: 笑笑
 * @DATE: 2021/11/6
 * @TIME: 下午 03:16
 */
@Service
public class UserServiceImple implements UserService {

    @Autowired
    private UserMapper userMapper;

    //根据用户名查询用户
    @Override
    public Integer getByName(String createName) {
        return userMapper.getByName(createName);
    }

    @Override
    public Boolean updateUser(User user) {
        if(user.getPassword() != null){
            String s = MD5Util.md5(user.getPassword());
            user.setPassword(s);
        }
        Boolean aBoolean = userMapper.updateUser(user);
        return aBoolean;
    }

    //查询所有的用户
    @Override
    public List<User> getAllUser(User user) {
        return userMapper.getAllUser(user);
    }

    //根据id查询用户
    @Override
    public User getById(Integer id) throws Exception {
        if (id == null || id <= 0){
            throw new Exception("id不正确");
        }
        return userMapper.getById(id);
    }

    //添加一个用户
    @Override
    public Boolean addUser(User user) {
        return userMapper.addUser(user);
    }
}
